import { Component, Input ,Output ,EventEmitter, forwardRef } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'

@Component({
  selector: "search-bar",
  templateUrl: "search-bar.html",
  providers: [{
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => SearchBarComponent),
    multi: true
  }]
})
export class SearchBarComponent {
  
  @Input() keyWord: string;
  @Input() placeholder = "请输入您要搜索的内容";
  @Output() onSearch = new EventEmitter<any>();
  @Output() onCancel = new EventEmitter<any>();

  constructor(){
  }

  onSearchEnter() {
    this.onSearch.emit(this.keyWord);
  }

  clickCancel() {
    this.onCancel.emit();
  }

  writeValue(val: string): void {
    this.keyWord = val;
  }

  registerOnChange(fn: any): void {
  }

  registerOnTouched(fn: any): void {
  }

  setDisabledState?(isDisabled: boolean): void {
  }
  
}
